let closePwdIcon = document.querySelector('.closePwd')
let editPwd = document.querySelector('.editPwd')


//关闭弹窗
let closePwd = function () {
    editPwd.style.display = 'none'
}
//打开弹窗
let openPwd = function () {
    editPwd.style.display = 'block'
}

function savePwd() {
    let oldPwd = document.querySelector('#oldPwd').value
    let newPwd = document.querySelector('#newPwd').value
    let confirmPwd = document.querySelector('#confirmPwd').value
    if (newPwd !== confirmPwd) {
        swal('更新密码失败', '两次密码不一致', 'error')
        return
    }
    if (!oldPwd || !newPwd || !confirmPwd) {
        swal('更新密码失败', '请填写完整信息', 'error')
        return
    }
    //密码大于6位
    if (newPwd.length < 6) {
        swal('更新密码失败', '密码长度不能小于6位', 'error')
        return
    }
    axios.post('/my/updatePwd', {
        oldPwd,
        newPwd
    }, {
        headers: {
            'authorization': localStorage.getItem('token')
        }
    }).then((res) => {
        if (res.data.status === 1) {
            swal('更新密码失败', `${res.data.message}`, 'error')
        }
        else {
            swal('更新密码成功', '即将返回', 'success')
            closePwd()
        }
    }).catch(
        (err) => {
            swal('更新密码失败', `${err}`, 'error')
        }
    )
}

